/// @file MovingObject.cpp
/// @brief inherits a basic static object and extends it to add movement and orientation
/// functionalities. this is the base of all moving entities in the flocking system

#include "MovingObject.h"

MovingObject::MovingObject
                    (
                        const ngl::Vector _pos,
                        const ngl::Vector _vel
                    ) :
                    StaticObject(_pos)
{
    //initialise params
    m_angleOfPitch = 0;
    m_angleOfYaw = 0;

    m_velocity.set(_vel);

    //initialise orientation
    updateOrientation();
}

void MovingObject::move(const ngl::Vector _velocity)
{
    //move to next postion (take into account velocity and orientation)

    //add velocity to position
    m_position += _velocity;

    //update orientation
    updateOrientation();
}

void MovingObject::updateOrientation()
{
    //calculate phi/latitude
    m_angleOfYaw = atan2(m_velocity.m_z, m_velocity.m_x) * (180.0 / M_PI);

    //calculate theta/longitude/azimuth
    if (m_velocity.length() < 0.001)
        m_angleOfPitch = 0;
    else
        m_angleOfPitch = asin(m_velocity.m_y / m_velocity.length()) * (180.0 / M_PI);
}

